package com.cdty.chess.controller;

import com.cdty.chess.model.Room;
import com.cdty.chess.service.RoomService;
import com.cdty.chess.vo.RoomVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/room")
public class RoomController {

    @Autowired
    RoomService service;

    /**
     * 新增
     * @param room
     */
    @PostMapping("/addRoom")
    public String addRoom(@RequestBody Room room){
        return service.addRoom(room);
    }

    /**
     * 逻辑删除
     * @param rid
     */
    @GetMapping("/delRoom")
    public String delRoom(@RequestParam String rid){
        String result = service.updateRoom(rid);
        return result;
    }

    /**
     * 逻辑删除
     * @param
     */
    @PostMapping("/updateRoom")
    public String updateRoom(@RequestBody Room room){
        String result = service.update(room.getUid(),room.getId());
        return result;
    }

    /**
     * 查询所有房号
     * @param
     */
    @GetMapping("/queryRoom")
    public List<RoomVo> queryRoom(@RequestParam(required = false) String rname ){
        List<RoomVo> result = service.queryRoom(rname);
        return result;
    }
}
